<?php

// $Id$


require_once(TANGRA_MAIN_DIR.'form/gform_ctrl_with_obj.class.php');

require_once('admin_user_chpwd_form.class.php');
require_once('admin_user_chpwd_form_view.class.php');

require_once($WSC->get_site_inc_dir().'modules/admin_panel/classes/admin_user/admin_user_dbc.class.php');


class Admin_User_Chpwd_Form_Ctrl extends GForm_Ctrl_With_Object {
	protected function create_form() {
		$form = new Admin_User_Chpwd_Form();

//		$form->generate_html();
		return $form;
	}


	protected function create_form_view() {
		$ret = new Admin_User_Chpwd_Form_View($this->form);

		return $ret;
	}


	protected function on_good_submit() {
		$ret = true;

		if ($this->form->get_field_value('password') == $this->form->get_field_value('password2')) {
			if ($ret) {
				if (tangra_strlen($this->form->get_field_value('password2')) <= 4) {

					$this->form->set_field_error('password2', 'weak_password');

					$ret = false;
				}
			}
		} else {
			$this->form->set_field_error('password2', 'passwords_not_match');
			$ret = false;
		}

		return $ret;
	}


	protected function on_bad_submit() {

//		printbr('lajna');
	}


	protected function create_object() {
		$object = new Admin_User_DBC();

		return $object;
	}


	protected function transfer_obj2form() {
		$object = $this->get_object();
		$form = $this->get_form();
	}


	protected function transfer_form2obj() {
		$object = $this->get_object();
		$form = $this->get_form();

		$object->set_password($form->get_field_value('password'));
	}
}